﻿import { PagedRequestDto } from "@shared/component-base";

export interface ICategoryDto {
  id:number;
  name:string;
  parentId:number;
  updatedTime:string;
  updatorName:string;
  level: number;
  expand: boolean;
  children?:ICategoryDto[]
}

export class CategoryDto implements ICategoryDto {
  id:number;
  name:string;
  parentId:number;
  updatedTime:string;
  updatorName:string;
  level: number;
  expand: boolean;
  children?:CategoryDto[]
}

export class CategoryListQueryDto extends PagedRequestDto {
  phone: string;
  keywords: string;

  init(data?: any) {
    if (data) {
      this.pageIndex = data["pageIndex"];
      this.pageSize = data["pageSize"];
      this.sortField = data["sortField"];
      this.sortOrder = data["sortOrder"];
      this.keywords = data["keywords"];
    }
  }

  toJSON(data?: any) {
    data = typeof data === 'object' ? data : {};
    data["pageIndex"] = this.pageIndex;
    data["pageSize"] = this.pageSize;
    data["sortField"] = this.sortField;
    data["sortOrder"] = this.sortOrder;
    data["keywords"] = this.keywords;
    return data;
  }
}

export interface ICategoryEditDto {
  id:number;
  name:string;
  parentId:string;
  keywords:string;
  orderNo:number;
}

export class CategoryEditDto implements ICategoryEditDto {
  id:number;
  name:string;
  parentId:string;
  keywords:string;
  orderNo:number;

  constructor(data?: ICategoryEditDto) {
    if (data) {
      for (var property in data) {
        if (data.hasOwnProperty(property))
          (<any>this)[property] = (<any>data)[property];
      }
    }
  }

  init(data?: any) {
    if (data) {
      this.id = data["id"];
      this.name = data["name"];
      this.parentId = data["parentId"]+'';
      this.keywords = data["keywords"];
      this.orderNo = data["orderNo"];
      
    }
  }

  static fromJS(data: any): CategoryEditDto {
    data = typeof data === 'object' ? data : {};
    let result = new CategoryEditDto();
    result.init(data);
    return result;
  }

  toJSON(data?: any) {
    data = typeof data === 'object' ? data : {};
      data["id"]=this.id;
      data["name"]=this.name;
      data["parentId"]=this.parentId;
      data["keywords"]=this.keywords;
      data["orderNo"]=this.orderNo;

    return data;
  }

  clone() {
    const json = this.toJSON();
    let result = new CategoryEditDto();
    result.init(json);
    return result;
  }
}


